package com.baidu.img.servlet;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.springframework.data.mongodb.core.MongoTemplate;

import com.baidu.user.bean.Image;
import com.mongodb.Mongo;



public class ImgServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;

	
	public void init() throws ServletException {
		
		MongoTemplate template = new MongoTemplate(new Mongo("127.0.0.1", 27017), "gjf");
		
		List<Image> list = template.findAll(Image.class,"image");
		
		ServletContext context = getServletContext();
		
		int i = 1;
		
		for (Image image : list) {
			
			context.setAttribute("img"+i, image.getUrl());
			
			i++;
		}
	}

	


	
	

}
